/**************************************************************

Copyright Astrium Services GEO-Information / Spot Image
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

 ***************************************************************/
package com.spotimage.catalog.client.event;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.spotimage.catalog.client.json.JSONSearchResult;

/**
 * Event to notify a new available search result
 */
public class SearchResultEvent extends GwtEvent<SearchResultEvent.Handler> {

	/** search result */
	private JSONSearchResult searchResult;

	/**
	 * Interface to describe this event. Handlers must implement.
	 */
	public interface Handler extends EventHandler {
		public void onSearchResult(SearchResultEvent e);
	}
	
	/**
	 */
	public SearchResultEvent() {
	}

	/**
	 * Should only be called by {@link HandlerManager}. In other words, do not
	 * use or call.
	 * 
	 * @param handler handler
	 */
	@Override
	protected void dispatch(SearchResultEvent.Handler handler) {
		handler.onSearchResult(this);
	}

	/**
	 * Returns the type used to register this event. Used by handler manager to
	 * dispatch events to the correct handlers.
	 * 
	 * @return the type
	 */
	@Override
	public GwtEvent.Type<SearchResultEvent.Handler> getAssociatedType() {
		return TYPE;
	}

	/**
	 * Returns the search result.
	 * @return
	 */
	public JSONSearchResult getSearchResult() {
		return searchResult;
	}

	/**
	 * Event type.
	 */
	public static final GwtEvent.Type<SearchResultEvent.Handler> TYPE = new GwtEvent.Type<SearchResultEvent.Handler>();

	/**
	 * Set searchResult object.
	 * @param searchResult
	 */
	public void setSearchResult(JSONSearchResult searchResult) {
		this.searchResult = searchResult;
	}

}
